package com.hiof.location.earcon;

import com.hiof.R;
import com.hiof.data.MoraService;
import com.hiof.servercommunication.receive.beans.GeoPoint;
import com.hiof.servercommunication.receive.beans.TargetInfoPacket;

import java.util.Timer;

/**
 * Created with IntelliJ IDEA.
 * User: manish
 * Date: 4/18/12
 * Time: 6:46 PM
 * To change this template use File | Settings | File Templates.
 */
public class BeepingNotificationManager extends EarconManager {

    private static BeepingNotificationManager instance;
    private boolean isPlayingSound = false; //flag
    private com.google.android.maps.GeoPoint targetPoint;
    private Timer playEarconTimer;
    private static final int TIME_INTERVAL = 5000;
    EarconPlayer earconPlayer;


    private BeepingNotificationManager() {
        earconPlayer = new EarconPlayer();
        earconPlayer.addEarcon("[beep]", "com.hiof", R.raw.metalhit);
    }

    public static BeepingNotificationManager getInstance() {
        if (instance == null) {
            instance = new BeepingNotificationManager();
        }
        return instance;
    }

    private void play() {
        earconPlayer.playEarcon();
    }

    @Override
    public void updateLocationChanged(GeoPoint geoPoint) {
//        if (isPlayingSound) {
        TargetInfoPacket nextTargetInfo = MoraService.getInstance().getNextTargetInfo();
//            TODO calculate this distance in client and put condition like if below distance is less than 700 meters then calculate in client
        double distance = nextTargetInfo.getDistance();
        if (distance < 700) {
            play();
//                stopContiniousEarcon();
//                playContiniousEarcon(3000);
        } else if (distance < 300) {
            play();
//                stopContiniousEarcon();
//                playContiniousEarcon(2000);
        } else if (distance < 600) {
            play();
        } else if (distance < 50) {

//                stopContiniousEarcon();
        }
    }
//    }


    @Override
    public void destroy() {
        //TODO: finalize here
    }
}

